package cn.wolfcode.luowowo.airticket.service.impl;

import cn.wolfcode.luowowo.airticket.domain.FlightDestination;
import cn.wolfcode.luowowo.airticket.mapper.FlightDestinationMapper;
import cn.wolfcode.luowowo.airticket.service.IFlightDestinationService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class FlightDestinationServiceImpl implements IFlightDestinationService {

    @Autowired
    private FlightDestinationMapper flightDestinationMapper;


    @Override
    public List<FlightDestination> queryisHot() {

        return flightDestinationMapper.queryisHot(1);
    }

    @Override
    public List<FlightDestination> queryInitial(String initials) {

        List<FlightDestination> result = new ArrayList<>();

        for (String initial : initials.split(",")) {

            List<FlightDestination> flightDestinations = flightDestinationMapper.queryInitial(initial);

            if (flightDestinations.size() > 0){

                for (FlightDestination flightDestination : flightDestinations) {
                    result.add(flightDestination);
                }
            }

        }
        return result;
    }
}
